package dataS.queue;

public class MyCycleQueue {
    private int[] array = null;
    //有效数据大小
    private int elements;
    //队头
    private int front;
    //队尾
    private int end;

    public MyCycleQueue(){
        array=new int [10];
        front=0;
        end=-1;
    }
    public MyCycleQueue(int size){
        array=new int[size];
        front=0;
        end=-1;
    }
    //从队尾插入
    public void insert(int value){
        //有四个数据,end=3,再插入的时候判断是3就重置
        if(end==array.length-1)
            end=-1;
        array[++end]=value;
        elements++;
    }
    //队头删除
    public int remove(){
        //删除0个，front=0;删除4个后，front=4;再删除就重置
        if(front==array.length)
            front=0;
        elements--;
        return array[front++];
    }
    //从队头查看数据
    public int peek(){
        return array[front];
    }
    //判断是否为空
    public boolean empty(){
        if(elements==0)
            return true;
        return false;
    }
    //判断是否满了
    public boolean isFull(){
        if(elements==array.length)
            return true;
        return false;
    }



}
